'''
Author: Kivvvvi 3385856680@qq.com
Date: 2024-11-08 15:20:20
LastEditors: Kivvvvi
LastEditTime: 2024-11-10 21:04:55
Description: api_test
'''
import api
import json
import numpy as np

sql_query = "SELECT date, open, close FROM daily_stock_data WHERE stock_code = '000001' ORDER BY date"
# sql_query = "SELECT date, open, close FROM daily_stock_data WHERE stock_code = '000001' limit 5"
# sql_query = "DROP * FROM daily_stock_data WHERE stock_code = '000001'"

# # use directly
# matrix = np.array(api.fetch_data_matrix(sql_query))
# print(matrix)
# print(matrix.shape)
# print(matrix.T)

# save as json file
result = api.fetch_data_matrix(sql_query)
print(type(result))
if isinstance(result, list):
    with open("data.json", "w") as f:
        json.dump(result, f)
    print("Data fetched successfully.")
else:
    print(result)
    
querier = api.Querier()
# df = querier.get_stocks_daily(["stock_code", "date", "close"], ["000001"], "2020-02-03", "2020-02-07")
# print(df)
df = querier.get_stocks_pivot("close", ["000001", "000002"], "2020-02-03", "2020-02-07")
print(df)